package com.test.model;

import io.netty.channel.Channel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author mkl
 * @Date 2021/5/26 18:38
 * @Description
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Connection {
    private Channel channel;
    private String imei;

    public static Connection getConnection(String imei) {
        return ConnectionManager.connections.get(imei);
    }

    public void register(Connection conn) {
        conn.getChannel().attr(ConnectionManager.connection).set(conn);
        ConnectionManager.addConnection(conn);
    }

    public void logOut() {
        ConnectionManager.removeConnection(this);
        this.getChannel().attr(ConnectionManager.connection).remove();
        this.channel.close();
    }


}
